"""
语法:
    1. js代码: window.scrollTo(0,100)
    2. 使用python执行js代码
        driver.execute_script(js代码)
"""

# 1. 导入需要的包
import os
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By

# 2. 创建浏览器驱动,并打开浏览器
driver = webdriver.Chrome()
driver.maximize_window()
driver.get(os.path.abspath("../练习页面/注册A.html"))

# 3. 元素定位+元素操作
select_tag = driver.find_element(By.ID, "selectA")
select_tag.find_element(By.XPATH, "//option[3]").click()

# 3.1 滚动条操作
sleep(2)
js_down = "window.scrollTo(0,500)"
driver.execute_script(js_down)

sleep(3)
js_up = "window.scrollTo(0,0)"  # js向上回到原点
driver.execute_script(js_up)

sleep(3)
driver.quit()
